package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.iview.ITrainingBulletinView;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

import android.content.Context;
import android.text.Html;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 培训公告
 *
 * @author Administrator
 */
@EViewGroup(R.layout.item_training_bulletin)
public class TrainingBulletinItemView extends LinearLayout {
    @ViewById
    TextView haveSignedText, newsTitleText, newsContentText;
    @ViewById
    ImageView newsContentImage;
    @ViewById
    Button trainingBulletinSignUp;
    /**
     * 新闻服务
     */
    ITrainingBulletinView iTrainingBulletinView;

    int position = -1;

    public TrainingBulletinItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public TrainingBulletinItemView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public void setiTrainingBulletinView(
            ITrainingBulletinView iTrainingBulletinView) {
        this.iTrainingBulletinView = iTrainingBulletinView;
    }

    /**
     * 加载数据
     *
     * @param position
     */
    public void loadData(int position, JSONObject newseJsonObject,
                         BitmapLoader bitmapLoader) {
        this.position = position;
        newsTitleText.setText(TypeUtils.getJsonString(newseJsonObject,
                "subject", ""));
        newsContentText.setText(TypeUtils.getJsonString(newseJsonObject,
                "desc", ""));
        // ImageLoader.getInstance().displayImage(
        // TypeUtils.getJsonString(newseJsonObject, "image"),
        // newsContentImage, options);
        //
        bitmapLoader.displayImage(
                TypeUtils.getJsonString(newseJsonObject, "image"),
                newsContentImage);
        haveSignedText.setText(String.valueOf(
                TypeUtils.getJsonInteger(newseJsonObject,
                        "applicants")));

        boolean applied = TypeUtils.getJsonBoolean(newseJsonObject, "applied",
                false);
        if (applied) {
//            trainingBulletinSignUp.setText("已报名");
        } else {
//            trainingBulletinSignUp.setText(R.string.signUpStr);
        }
    }

    @Click(R.id.trainingBulletinSignUp)
    public void signUp() {

        if (iTrainingBulletinView != null) {
            iTrainingBulletinView.signUp(position);
        }
    }
}
